//
//  SHGuideViewController.m
//  UI_CarHome
//
//  Created by dllo on 15/11/5.
//  Copyright (c) 2015年 沈浩. All rights reserved.
//

#import "SHGuideViewController.h"
#import "SHHandle.h"
#import "SHRecommendViewController.h"
@interface SHGuideViewController ()<UIScrollViewDelegate>
@property(nonatomic, retain)UIPageControl *pageControl;
@end

@implementation SHGuideViewController

- (void)dealloc
{
    Block_release(_block);
    [_pageControl release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor redColor];
    
    [self initGuide]; // 加载新用户指导页面
    
    self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(WIDTH / 2 - 75, HEIGHT, 150, 40)];
    self.pageControl.numberOfPages = 4;
    self.pageControl.pageIndicatorTintColor = [UIColor grayColor];
    [self.view addSubview:self.pageControl];
    [_pageControl release];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    self.pageControl.currentPage = scrollView.contentOffset.x / WIDTH;
}

- (void)initGuide {
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    scrollView.contentSize = CGSizeMake(WIDTH * 4, 0);
    scrollView.pagingEnabled = YES;
    [scrollView setBounces:NO]; //避免弹跳效果
    // 隐藏水平滚动条
    scrollView.showsHorizontalScrollIndicator = NO;
    
    for (NSInteger i = 0; i < 4; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH * i, 0, WIDTH, HEIGHT)];
        imageView.image =[UIImage imageNamed:[NSString stringWithFormat:@"ya%ld.jpg", i]];
        [scrollView addSubview:imageView];
        [imageView release];
        
        UIButton *guideButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [scrollView addSubview:guideButton];
        guideButton.frame = CGRectMake(WIDTH * 3 + WIDTH / 2, HEIGHT - 60, 230, 37);
        [guideButton setTitle:@"立即启程" forState:UIControlStateNormal];
        [guideButton addTarget:self action:@selector(guideButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    [self.view addSubview:scrollView];
    [scrollView release];
    
}

- (BOOL)prefersStatusBarHidden {
    return YES;
}

- (void)guideButtonAction:(UIButton *)button {
    // 调用block
    self.block();
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
